#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import jsonify, request
from flask_restful import Resource
from utility.odoo_manager import OdooManager  # 操作odoo的单例
from utility.error_code import error_code  # 异常代码
from utility.message_manager import MessageBusManager
from event import event_type
from utility import tools
from command import command
import logging

FORMAT = "%(asctime)s %(thread)d %(message)s"
logging.basicConfig(level=logging.INFO, format=FORMAT)

class HighRiskFollowupTasksListAPI(Resource):
    """
    高危随访列表
    :request: post
    :param status: 状态 null 全部 0 未随访 1已随访
    :param rwsjStart: 任务时间开始
    :param rwsjEnd: 任务时间结束
    :param sfsjStart: 随访时间开始
    :param sfsjEnd: 随访时间结束
    :param jdlx: 建档类型 null 全部 1 本院建档 2外院建档
    :param jdjgCode: 建档机构Code
    :param mcyjStartDate: 末次月经开始时间
    :param mcyjEndDate: 末次月经结束时间
    :param searchText: 搜索字符串
    :param rwlx: 任务类型
    :param isAsc：排序方向 排序的方向,示例值(asc,desc)
    :param orderByColumn：排序列
    :param pageNum：当前页数
    :param pageSize: 分页大小
    :returns: json string
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def post(self):
        try:
            odoo = OdooManager().get_instance()
            params = tools.get_params(request)
            is_asc = params.get('isAsc') if params.get('isAsc', False) else 'asc'
            order_by_column = params.get('orderByColumn') if params.get('orderByColumn', False) else 'create_date'
            #  构造排序方式
            order_ =  order_by_column+' '+ is_asc
            #  初始化页数,返回数据条数,偏移
            page = int(params.get('pageNum')) if params.get('pageNum', False) else 1
            pagesize = int(params.get('pageSize')) if params.get('pageSize', False) else 10
            offset = page * pagesize - pagesize
            #  构造查询条件 status
            query_ = []
            if params.get('status'): # 状态 null 全部 0 未随访 1已随访
                query_.append(('state', '=', params.get('status')))
            if params.get('rwsjStart'): # 任务时间开始
                query_.append(('create_date', '>=', params.get('rwsjStart')))
            if params.get('rwsjEnd'): # 任务时间结束
                query_.append(('create_date', '<=', params.get('rwsjEnd')))
            if params.get('sfsjStart'): # 随访时间开始
                query_.append(('start_time', '>=', params.get('sfsjStart')))
            if params.get('sfsjEnd'): # 随访时间结束
                query_.append(('end_time', '<=', params.get('sfsjEnd')))
            query_t_=[]     
            if params.get('jdlx'): # 建档类型 null 全部 1 本院建档 2外院建档
                query_t_.append(('jd_sfby', '=', params.get('jdlx')))                      
            if params.get('jdjgCode'): # 建档机构Code
                query_t_.append(('jd_dw', '=', params.get('classifyId')))
            if params.get('mcyjStartDate'): # 末次月经开始时间
                query_t_.append(('mcyjsj', '>=', params.get('mcyjStartDate')))   
            if params.get('mcyjEndDate'): # 末次月经结束时间
                query_t_.append(('mcyjsj', '<=', params.get('mcyjEndDate'))) 
            if params.get('searchText'): # 搜索字符串
                query_t_.append(('mq_xm', 'ilike', int(params.get('searchText'))))  # 孕妇姓名  
                query_t_.append(('mq_sjhm', 'ilike', int(params.get('searchText')))) # 孕妇手机号码        
            if query_t_:
                res_archives = odoo.env['res.archives'].search_read(query_t_,['id'])
                if res_archives:
                    archives_ids = [archives['id']  for archives in res_archives]
                    query_.append(('archives_id', 'in', archives_ids))
            fields = [
                    'name','id','follow_data_type','follow_type','user_id',
                    'follow_yz','start_time','end_time','state','archives_id'
                    ]    
            ins_follow_recall = odoo.env['inspection.follow.recall'].search_read(query_,fields,  offset = offset, limit = pagesize, order = order_)
            data_ = {'dataList': [],'total': 0}
            if ins_follow_recall:
                for  ins_follow_recall_ in ins_follow_recall:
                    fields_t_ = ['mq_cz_address','mq_xm','mq_mz','mq_age','max_gwys'
                            ,'sccjrq','jd_date','jd_dw'
                        ]
                    res_archives = odoo.env['res.archives'].search_read([('id','=',ins_follow_recall_['archives_id'][0])],fields_t_)    
                    if res_archives:
                        res_archive = res_archives[0]
                        data_tmp={
                            'rwbh': ins_follow_recall_['name'],
                            'id': ins_follow_recall_['id'],
                            'rwlx': ins_follow_recall_['follow_data_type'],
                            'sffs': ins_follow_recall_['follow_type'],
                            'mqXm': res_archive['mq_xm'],
                            'mqZz': res_archive['mq_cz_address'],
                            'mqMz': res_archive['mq_mz'],
                            'mqAge': res_archive['mq_age'],
                            'yz': ins_follow_recall_['follow_yz'],
                            'gwColorCode': res_archive['max_gwys'],
                            'sccjsj': res_archive['sccjrq'],
                            'jdsj': res_archive['jd_date'],
                            'jdjgName': res_archive['jd_dw'][1] if res_archive['jd_dw'] else None,
                            'sffqsj': ins_follow_recall_['start_time'],
                            'sfwcsj': ins_follow_recall_['end_time'],
                            'sfr': ins_follow_recall_['user_id'][1] if ins_follow_recall_['user_id'] else None,
                            'status': ins_follow_recall_['state']
                        }
                        data_['dataList'].append(data_tmp)
            data_['total'] = odoo.env['inspection.follow.recall'].search_count(query_)
            return jsonify({'code': 0, 'msg': 'success', 'data': data_, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class HighRiskFollowupRecAddAPI(Resource):
    """
    生成高危随访-执行高危随访登记
    :request: post
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def post(self):
        try:
            odoo = OdooManager().get_instance()
            params = tools.get_params(request)
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
                'archives_id': params.get('archivesId'),
                'follow_data_type': '0',
                'user_id': params.get('sfrCode'),
                'state': '1',
                'start_time': params.get('sfSj'),
                'end_time': params.get('sfSj'),
                'hospital_id': 1
            }
            data_ = odoo.env['inspection.follow.recall'].create(data_)
            create_event = event_type.OperationLogEvent('生成高危随访-执行高危随访登记', 'id:{}'.format(data_))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': data_}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class HighRiskFollowupRecUpdateAPI(Resource):
    """
    修改高危随访登记记录
    :request: put
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def put(self):
        try:
            odoo = OdooManager().get_instance()
            params = request.json
            # 参数校验
            req_params = ['id','sffs','sfyz','zdyj','zdnr']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            query_ = [('id', '=', params.get('id'))]
            res_config_template = odoo.env['inspection.follow.recall'].search(query_)
            if not res_config_template:
                return jsonify({'code': 40005, 'msg': error_code[40005]})
            # 修改高危随访登记记录
            data_ = {
                'id': params.get('id'),
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
                'hospital_id': 1,
                'user_id': params.get('sfrCode'),
                'state': '1',
                'end_time': params.get('sfSj')
            }
            odoo.env['inspection.follow.recall'].write(res_config_template, data_)
            create_event = event_type.OperationLogEvent('修改高危随访登记记录', 'id:{}'.format(params.get('id')))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': params.get('id')}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class RecallFollowupRecAddAPI(Resource):
    """
    生成产前筛查高危风险召回随访
    :request: post
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param sfwfjt: 是否无法接通
    :param zhjg: 召回结果
    :param zgjgsbYy: 召回结果失败原因
    :param zhryycfgx: 召回人与孕产妇关系
    :param zhryycfgxQt: 召回医生Code
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def post(self):
        try:
            odoo = OdooManager().get_instance()
            params = tools.get_params(request)
            # 参数校验
            req_params = ['sffs','sfyz','sfwfjt','zhjg','zgjgsbYy','zhryycfgx','zhryycfgxQt','zdyj','zdnr']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            # 生成产前筛查高危风险召回随访
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'through_to': params.get('sfwfjt'),
                'call_res': params.get('zhjg'),
                'call_res_remark': params.get('zgjgsbYy'),
                'call_back_remark': params.get('zhryycfgx'),
                'call_back_doctor': params.get('zhryycfgxQt'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
            }
            if params.get('id'):
                query_ = [('id', '=', params.get('id'))]
                res_config_template = odoo.env['inspection.follow.recall'].search(query_)
                if not res_config_template:
                    return jsonify({'code': 40005, 'msg': error_code[40005]})
                data_['id'] = params.get('id')     
                data_ = odoo.env['inspection.follow.recall'].write(res_config_template,data_)
                create_event = event_type.OperationLogEvent('修改产前筛查高危风险召回随访', 'id:{}'.format(params.get('id')))
                message_bus = MessageBusManager().get_message_bus()
                message_bus.handle(create_event)  # 发布事件
            else:    
                data_ = odoo.env['inspection.follow.recall'].create(data_)
                create_event = event_type.OperationLogEvent('生成产前筛查高危风险召回随访', 'id:{}'.format(data_))
                message_bus = MessageBusManager().get_message_bus()
                message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': data_}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class RecallFollowupRecUpdateAPI(Resource):
    """
    修改产前筛查高危风险召回随访
    :request: put
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param sfwfjt: 是否无法接通
    :param zhjg: 召回结果
    :param zgjgsbYy: 召回结果失败原因
    :param zhryycfgx: 召回人与孕产妇关系
    :param zhryycfgxQt: 召回医生Code
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def put(self):
        try:
            odoo = OdooManager().get_instance()
            params = request.json
            # 参数校验
            req_params = ['id']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            query_ = [('id', '=', params.get('id'))]
            res_config_template = odoo.env['inspection.follow.recall'].search(query_)[0]
            if not res_config_template:
                return jsonify({'code': 40005, 'msg': error_code[40005]})
            # 修改产前筛查高危风险召回随访
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'state': '1',
                'end_time': params.get('sfSj'),
                'through_to': params.get('sfwfjt'),
                'call_res': params.get('zhjg'),
                'call_res_remark': params.get('zhjgOther'),
                'call_back_remark': params.get('zhyyfgx'),
                'cf_relation_remark': params.get('zhyyfgxOther'),
                'call_back_doctor': params.get('zhysCode'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
                'hospital_id': 1,
                'user_id': params.get('sfrCode'),
            }
            odoo.env['inspection.follow.recall'].write(res_config_template, data_)
            create_event = event_type.OperationLogEvent('修改产前筛查高危风险召回随访', 'id:{}'.format(params.get('id')))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': params.get('id')}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class PreOutFollowupRecAddAPI(Resource):
    """
    生成产前筛查高危风险妊娠结局随访
    :request: post
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param sfwfjt: 是否无法接通
    :param fmyyCode: 分娩医院
    :param fmfs: 分娩方式
    :param rsjj: 妊娠结局
    :param rsjjycYy: 妊娠结局异常原因
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def post(self):
        try:
            odoo = OdooManager().get_instance()
            params = tools.get_params(request)
            # 参数校验
            req_params = ['sffs','sfyz','sfwfjt','fmyyCode','fmfs','rsjj','rsjjycYy','zdyj','zdnr']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            # 生成产前筛查高危风险妊娠结局随访
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'through_to': params.get('sfwfjt'),
                'fm_hospital': params.get('fmyyCode'),
                'fm_type': params.get('fmfs'),
                'rc_ju': params.get('rsjj'),
                'rc_ju_remark': params.get('rsjjycYy'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
            }
            if params.get('id'):
                query_ = [('id', '=', params.get('id'))]
                res_config_template = odoo.env['inspection.follow.recall'].search(query_)
                if not res_config_template:
                    return jsonify({'code': 40005, 'msg': error_code[40005]})
                data_['id'] = params.get('id')     
                data_ = odoo.env['inspection.follow.recall'].write(res_config_template,data_)
                create_event = event_type.OperationLogEvent('修改产前筛查高危风险妊娠结局随访', 'id:{}'.format(params.get('id')))
                message_bus = MessageBusManager().get_message_bus()
                message_bus.handle(create_event)  # 发布事件
            else:
                data_ = odoo.env['inspection.follow.recall'].create(data_)
                create_event = event_type.OperationLogEvent('生成产前筛查高危风险妊娠结局随访', 'id:{}'.format(data_))
                message_bus = MessageBusManager().get_message_bus()
                message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': data_}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class PreOutFollowupRecUpdateAPI(Resource):
    """
    修改产前筛查高危风险妊娠结局随访
    :request: put
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param sfwfjt: 是否无法接通
    :param fmyyCode: 分娩医院
    :param fmfs: 分娩方式
    :param rsjj: 妊娠结局
    :param rsjjycYy: 妊娠结局异常原因
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def put(self):
        try:
            odoo = OdooManager().get_instance()
            params = request.json
            # 参数校验
            req_params = ['id']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            query_ = [('id', '=', params.get('id'))]
            res_config_template = odoo.env['inspection.follow.recall'].search(query_)[0]
            if not res_config_template:
                return jsonify({'code': 40005, 'msg': error_code[40005]})
            # 修改产前筛查高危风险妊娠结局随访
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'through_to': params.get('sfwfjt'),
                'fm_hospital': params.get('fmyyCode'),
                'fm_type': params.get('fmfs'),
                'rc_ju': params.get('rsjj'),
                'rc_ju_remark': params.get('rsjjYcyy'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
                'hospital_id': 1,
                'user_id': params.get('sfrCode'),
                'state': '1',
                'end_time': params.get('sfSj'),
            }
            data_ = odoo.env['inspection.follow.recall'].write(res_config_template,data_)
            create_event = event_type.OperationLogEvent('修改产前筛查高危风险妊娠结局随访', 'id:{}'.format(params.get('id')))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': data_}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class PostpartumFollowupRecAddAPI(Resource):
    """
    生成产前筛查高危风险28天随访
    :request: post
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param sfwfjt: 是否无法接通
    :param sfjjjybjc: 是否拒绝进一步检查
    :param jcyyCode: 检查医院
    :param jcfs: 检查结果
    :param jcjgycYy: 检查结果异常原因
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def post(self):
        try:
            odoo = OdooManager().get_instance()
            params = tools.get_params(request)
            # 参数校验
            req_params = ['id','sffs','sfyz','sfwfjt','sfjjjybjc','jcyyCode','jcfs','jcjgycYy','zdyj','zdnr']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            # 生成产前筛查高危风险28天随访
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'through_to': params.get('sfwfjt'),
                'jyb_check': params.get('sfjjjybjc'),
                'check_hospital': params.get('jcyyCode'),
                'check_res': params.get('jcfs'),
                'check_res_remark': params.get('jcjgycYy'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
            }
            if params.get('id'):
                query_ = [('id', '=', params.get('id'))]
                res_config_template = odoo.env['inspection.follow.recall'].search(query_)
                if not res_config_template:
                    return jsonify({'code': 40005, 'msg': error_code[40005]})
                data_['id'] = params.get('id')     
                data_ = odoo.env['inspection.follow.recall'].write(res_config_template,data_)
                create_event = event_type.OperationLogEvent('修改产前筛查高危风险妊娠结局随访', 'id:{}'.format(params.get('id')))
                message_bus = MessageBusManager().get_message_bus()
                message_bus.handle(create_event)  # 发布事件
            else:
                data_ = odoo.env['inspection.follow.recall'].create(data_)
                create_event = event_type.OperationLogEvent('生成产前筛查高危风险28天随访', 'id:{}'.format(data_))
                message_bus = MessageBusManager().get_message_bus()
                message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': data_}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class PostpartumFollowupRecUpdateAPI(Resource):
    """
    修改产前筛查高危风险28天随访
    :request: put
    :param id: id
    :param sffs: 随访方式
    :param sfyz: 随访孕周
    :param sfwfjt: 是否无法接通
    :param sfjjjybjc: 是否拒绝进一步检查
    :param jcyyCode: 检查医院
    :param jcfs: 检查结果
    :param jcjgycYy: 检查结果异常原因
    :param zdyj: 指导意见
    :param zdnr: 指导内容
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def put(self):
        try:
            odoo = OdooManager().get_instance()
            params = request.json
            # 参数校验
            req_params = ['id']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            query_ = [('id', '=', params.get('id'))]
            res_config_template = odoo.env['inspection.follow.recall'].search(query_)[0]
            if not res_config_template:
                return jsonify({'code': 40005, 'msg': error_code[40005]})
            # 修改产前筛查高危风险妊娠结局随访
            data_ = {
                'follow_type': params.get('sffs'),
                'follow_yz': params.get('sfyz'),
                'through_to': params.get('sfwfjt'),
                'jyb_check': params.get('sfjjjybjc'),
                'check_hospital': params.get('jcyyCode'),
                'check_type': params.get('jcfs'),
                'check_res': params.get('jcjg'),
                'check_res_remark': params.get('jcjgYcyy'),
                'guidance_idea': params.get('zdyj'),
                'guidance_content': params.get('zdnr'),
                'hospital_id': 1,
                'user_id': params.get('sfrCode'),
                'state': '1',
                'end_time': params.get('sfSj'),
            }
            odoo.env['inspection.follow.recall'].write(res_config_template,data_)
            create_event = event_type.OperationLogEvent('修改产前筛查高危风险妊娠结局随访', 'id:{}'.format(params.get('id')))
            message_bus = MessageBusManager().get_message_bus()
            message_bus.handle(create_event)  # 发布事件
            return jsonify({'code': 0, 'msg': 'success', 'data': {'id': res_config_template}, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})

class FollowUpRecordQueryAPI(Resource):
    """
    根据任务类型回显随访记录
    :request: get
    :param id: id
    :returns: json string
    """
    #@AppSecurity.public_verify()
    #@AppSecurity.token_verify()
    def get(self):

        try:
            #  参数校验
            params = request.values
            req_params = ['id']
            vrf_res = tools.required_parame_verif(req_params,params)
            if  vrf_res['code'] != 0:
                return jsonify(vrf_res)
            #  根据任务类型回显随访记录
            odoo = OdooManager().get_instance()
            #  构造查询条件
            query_ = [('id', '=', int(params.get('id')))]   
            birth_uterus_record_ = odoo.env['inspection.follow.recall'].search_read(query_)
            data_ = {}
            if birth_uterus_record_:
                birth_uterus_record_=birth_uterus_record_.pop()
                data_ = {
                    'sffs': birth_uterus_record_['follow_type'],
                    'sfyz': birth_uterus_record_['follow_yz'],
                    'zdyj': birth_uterus_record_['guidance_idea'],
                    'zdnr': birth_uterus_record_['guidance_content'],
                    'sfwfjt': birth_uterus_record_['through_to'],
                    'zhjg': birth_uterus_record_['call_res'],
                    'zhjgOther': birth_uterus_record_['call_res_remark'],
                    'zhyyfgx': birth_uterus_record_['call_back_remark'],
                    'zhyyfgxOther': birth_uterus_record_['cf_relation_remark'],
                    'zhysCode': birth_uterus_record_['call_back_doctor'][0] if birth_uterus_record_['call_back_doctor'] else '',
                    'zhysName': birth_uterus_record_['call_back_doctor'][1] if birth_uterus_record_['call_back_doctor'] else '',
                    'fmyyCode': birth_uterus_record_['fm_hospital'][0] if birth_uterus_record_['fm_hospital'] else '',
                    'fmyyName': birth_uterus_record_['fm_hospital'][1] if birth_uterus_record_['fm_hospital'] else '',
                    'fmfs': birth_uterus_record_['fm_type'],
                    'rsjj': birth_uterus_record_['rc_ju'],
                    'rsjjYcyy': birth_uterus_record_['rc_ju_remark'],
                    'sfjjjybjc': birth_uterus_record_['jyb_check'],
                    'jcyyCode': birth_uterus_record_['check_hospital'][0] if birth_uterus_record_['check_hospital'] else '',
                    'jcyyName': birth_uterus_record_['check_hospital'][1] if birth_uterus_record_['check_hospital'] else '',
                    'jcfs': birth_uterus_record_['check_type'],
                    'jcjg': birth_uterus_record_['check_res'],
                    'jcjgYcyy': birth_uterus_record_['check_res_remark'],
                    'sfSj': birth_uterus_record_['end_time'],
                    'sfrCode': birth_uterus_record_['user_id'][0] if birth_uterus_record_['user_id'] else '',
                    'sfrName': birth_uterus_record_['user_id'][1] if birth_uterus_record_['user_id'] else '',
                    'id': birth_uterus_record_['id']
                }
            return jsonify({'code': 0, 'msg': 'success', 'data': data_, 'success': True})
        except AttributeError as e:
            logging.exception(e)
            return jsonify({'code': 404, 'msg': error_code[404]})
        except Exception as e:
            logging.exception(e)
            return jsonify({'code': 100, 'msg': error_code[100]})
